package com.eliza.demo.db.fg

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import androidx.core.text.isDigitsOnly
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.eliza.demo.R
import com.eliza.library.model.Contactor
import com.eliza.library.tools.InfoTools
import com.eliza.library.tools.TextTools


class InsertContactor : Fragment() {
    lateinit var holder: InsertContactorHolder
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var view = inflater.inflate(R.layout.fragment_contactor, container, false)
        holder = InsertContactorHolder(view)
        return view
    }

    /**
     * Get data
     * 从 fragment 中获取数据
     * @return
     */
    fun getData(): Contactor {
        InfoTools.LogTools("Aaaa", holder.cTel.text.toString())
        return Contactor(
            TextTools.StringToInt(holder.cId.text.toString()),
            holder.cName.text.toString(),
            TextTools.StringToInt(holder.cAge.text.toString()),
            TextTools.StringNullToBlank(holder.cTel.text.toString()),
            TextTools.StringNullToBlank(holder.aEml.text.toString())
        )
    }

    class InsertContactorHolder(view: View) {
        var cId = view.findViewById<EditText>(R.id.Contactor_data_id)
        var cName = view.findViewById<EditText>(R.id.Contactor_data_name)
        var cAge = view.findViewById<EditText>(R.id.Contactor_data_age)
        var cTel = view.findViewById<EditText>(R.id.Contactor_data_tel)
        var aEml = view.findViewById<EditText>(R.id.Contactor_data_email)
    }
}